<meta charset="UTF-8">
<body>
	<h3 style="text-align: center;">学生管理</h3>
	<div class="container" style="padding: 10px;">
	<!-- 查询对话框 -->
	<form id="searchForm">
			<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="myModalLabel">查询</h4>
						</div>
						<div class="modal-body">
						
						<div class="form-group">
								<label for="search_stuNo">学号：</label>
								<input id="search_stuNo" type="text" class="form-control" name="stuNo" placeholder="课时数">
							</div>
		        	<div class="form-group">
								<label for="search_name">姓名：</label>
								<input id="search_name" type="text" class="form-control" name="name" placeholder="课程名称">
							</div>
							
						
						</div>
						<div class="modal-footer">
							<button type="button" onclick="query()" class="btn btn-primary" data-dismiss="modal"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>&nbsp;查询</button>
							<button type="button" onclick="clearQuery()" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;清空</button>
						</div>
					</div>
				</div>
			</div>
		</form> 
	
		<form action="abc" method="post" class="form-horizontal">
			<div class="form-group">
				<label class="col-md-1 control-label">选择班级:</label>
				<div class="col-md-2">
					<input class="form-control" id="mytable2" type="text" />
				</div>
			</div>
			<hr />
			<div id="div" class="container" style="flex-grow: 1; display: none;">
				<table id="mytable">
					<thead>
						<tr>
							<th data-checkbox="true"></th>
							<!-- <th data-field="id">ID</th> -->
							<th data-field="stuNo">学号</th>
							<th data-field="name">姓名</th>
						</tr>
					</thead>
				</table>
			</div>
		</form>
	</div>
	
</body>
	<script type="text/javascript">
		function queryParams(param){
			var obj=$('#searchForm').serializeObject();
			obj.limit=param.limit;
			obj.offset=param.offset;
			obj.search=param.search;
			return obj;
		}
		
		function search(){
			var dialog=$('#searchForm').find('div[role="dialog"]');
			dialog.modal();
		}
		
		function query(){
			$('#mytable').bootstrapTable('selectPage',1);
		}
		
		function clearQuery(){
			$('#searchForm').form('clear');
			$('#mytable').bootstrapTable('selectPage',1);
		}
		
		
$(function(){
	$('#mytable2').combobox({
			url:'banji/list',
			valueField:'id',
			textField:'name',
		onchange:function(id){
			var grid=$('#mytable');
			$('#div').show();
			$('#mytable').datagrid({
				path:'student',
				url:'page?classId='+id,
				editUrl:'edit?classId='+id,
				deleteUrl:'delete?classId='+id,
				saveUrl:'save?classId='+id,
				searchUrl:'search',
				buttons:[$.fn.datagrid.toolbar.buttons.add,$.fn.datagrid.toolbar.buttons.edit,$.fn.datagrid.toolbar.buttons.search,$.fn.datagrid.toolbar.buttons.remove,
					$.createBtn({
						iconCls:'glyphicon glyphicon-user',
						text:'查看照片',
						handler:function(){
							var self=$(this);
							var grid=$.fn.datagrid.toolbar.grid(self);
							var selections=grid.bootstrapTable('getSelections');
							if(selections.length!=1){
								bootbox.alert('请先选择一名学生');
								return;
							}
							var stuId=selections[0].id;
							var dialog=$('<div style="display:none;"/>');
							dialog.appendTo($('body'));
							var img=$('<img alt="该用户还未上次图片"/>');
							img.attr('src','student/download?id='+stuId);
							img.attr('width','100%');
							dialog.append(img);
							var dia=$.createDialog({
								title:''
							}).on('hidden.bs.modal',function(){
								dia.remove();
							});
							dia.find('div.modal-dialog').find('div.modal-content').find('div.modal-body').append(img);
							dia.modal('show');
						}
						}),$.createBtn({
								iconCls:'glyphicon glyphicon-modal-window',
								text:'密码重置',
								handler:function(){
									var self=$(this);
									var grid=$.fn.datagrid.toolbar.grid(self);
									var selections=grid.bootstrapTable('getSelections');
									if(selections.length!=1){
										bootbox.alert('请先选择一名学生');
										return;
									}
									var stuId=selections[0].id;
									$.post('student/resetPwd',{id:stuId},function(result){
										bootbox.alert('密码重置成功，初始密码为1111');
									})
								}
							})]
				
				})
			}
		});
	});
</script>